package org.liveboardgames.agricola.model.structure;

import java.util.Map;

import org.liveboardgames.agricola.domain.action.Action;
import org.liveboardgames.agricola.domain.board.BoardTile;
import org.liveboardgames.agricola.domain.card.BakingImprovementCard;
import org.liveboardgames.agricola.domain.card.Card;
import org.liveboardgames.agricola.domain.card.CookingImprovementCard;
import org.liveboardgames.agricola.domain.card.ImprovementCard;
import org.liveboardgames.agricola.domain.common.AlternativeCost;
import org.liveboardgames.agricola.domain.farm.Farm;
import org.liveboardgames.agricola.domain.farm.FarmTile;
import org.liveboardgames.agricola.domain.player.Player;
import org.liveboardgames.common.util.ExternalMap;

public class GameSendVisitor implements Visitor {

  public void visit(Visitable visitable) {
    // TODO: for now only actions are needed
  }

  public void visit(Action action) {
    Map<String, Integer> externalMap = null;
    Map<String, Integer> cost = action.getCost();
    if (cost != null) {
      externalMap = new ExternalMap();
      externalMap.putAll(cost);
    }
    action.setCost(externalMap);
  }

  public void visit(Card card) {
    Map<String, Integer> externalMap = null;
    Map<String, Integer> resources = card.getResources();
    if (resources != null) {
      externalMap = new ExternalMap();
      externalMap.putAll(resources);
    }
    card.setResources(externalMap);
  }

  public void visit(Player player) {
    // TODO Auto-generated method stub

  }

  public void visit(BakingImprovementCard card) {
    // TODO Auto-generated method stub

  }

  public void visit(CookingImprovementCard card) {
    // TODO Auto-generated method stub

  }

  public void visit(ImprovementCard card) {
    Map<String, Integer> cost = card.getCost();
    Map<String, Integer> externalMap = null;
    if (cost != null) {
      externalMap = new ExternalMap();
      externalMap.putAll(cost);
    }
    card.setCost(externalMap);
  }

  public void visit(Farm farm) {
    Map<String, Integer> externalMap = null;
    Map<String, Integer> resources = farm.getResources();
    if (resources != null) {
      externalMap = new ExternalMap();
      externalMap.putAll(resources);
    }
    farm.setResources(externalMap);
  }

  public void visit(FarmTile farmTile) {
    Map<String, Integer> externalMap = null;
    Map<String, Integer> resources = farmTile.getResources();
    if (resources != null) {
      externalMap = new ExternalMap();
      externalMap.putAll(resources);
    }
    farmTile.setResources(externalMap);
  }

  public void visit(BoardTile boardTile) {
    Map<String, Integer> externalMap = null;
    Map<String, Integer> resources = boardTile.getResources();
    if (resources != null) {
      externalMap = new ExternalMap();
      externalMap.putAll(resources);
    }
    boardTile.setResources(externalMap);
  }

  public void visit(AlternativeCost alternativeCost) {
    Map<String, Integer> externalMap = null;
    Map<String, Integer> cost = alternativeCost.getCost();
    if (cost != null) {
      externalMap = new ExternalMap();
      externalMap.putAll(cost);
    }
    alternativeCost.setCost(externalMap);
  }

}
